
/* ********************************************************************************************
*  Alvin Baldemeca
*  Tetris Project
*  Course: TCSS 305 , Alan Fowler
*  Term: Spring 2012
*  UNIVERISTY OF WASHINGTON TACOMA
*
*
**********************************************************************************************/

package gui.actions;


import controller.Board;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;


import javax.swing.AbstractAction;
import javax.swing.Action;
import view.TetrisBoardPanel;






/**
 *This action tells a Board to move a tetris left.
 *@author Alvin Baldemeca
 *@version 5/25/2012
 */
@SuppressWarnings("serial")
public class SelectLevelAction extends AbstractAction
{
  
  /**
   * Then number of lines that need to be cleared to get to the next level.
   */
  private static final int NEXT_LEVEL = 20;
  
  /**
   * The panel to perform the action to.
   */
  private final Board my_board;
  
  /**
   * The level to set the difficulty of the tetris game to.
   */
  private final Integer my_level;
  
  /**
   * The tetris board panel that need to request focus after the action
   * was performed.
   */
  private final TetrisBoardPanel my_tetris_board_panel;
  
  
  /**
   * Creates a LeftAction.
   * @param the_board the board that controls the tetris piece
   * @param the_level the level to set the board to.
   * @param the_tetris_board_panel The tetris board panel that need to
   * request focus after the action was performed.
   */
  public SelectLevelAction(final Board the_board, 
                           final Integer the_level, 
                           final TetrisBoardPanel the_tetris_board_panel) 
  {
    super(the_level.toString());
    putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
    putValue(Action.SELECTED_KEY, true);
    my_board = the_board;
    my_level = the_level;
    my_tetris_board_panel = the_tetris_board_panel;
  }

  @Override
  public void actionPerformed(final ActionEvent the_event) 
  {
    my_board.setNumberOfLinesCleared(my_level * NEXT_LEVEL);
    my_tetris_board_panel.requestFocus();
  }
  

}